--
-- This Lua script implements a bunch of the "management" of applets, so you can modify it!
-- But most importantly, it it loaded before any script or configuration.
--
-- Written by Tomas Lindquist Olsen, Sep 27 2010
--

-- this function is called by the host app before the config is read
function init_lua_applets()
    print("[!] initializing lua-applets")

    SharedImage:set_root_directory(userconfigdir)
end

-- this is called when the host app is a about to shut down
function exit_lua_applets()
    print("[!] exitting lua-applets")
end

-- just return the full output of some command
function get_cmd_output(cmd)
    local p = io.popen(cmd.." 2>&1", "r")
    local c = p:read("*a")
    p:close()
    return c
end

-- return true if this command is available in the system
function has_cmd(cmd)
    -- this relies on the 'which' command for
    local r = os.execute('which "'..cmd..'" > /dev/null 2>&1')
    return r == 0
end
